package org.sean.common.evaluting;

import java.security.InvalidParameterException;

/**
 * 业务表达式
 */
public class BusinessExpression {

    /**
     * 表达式名称
     */
    private String name;

    /**
     * 表达式
     */
    private String expression;

    /**
     * 构造函数
     * @param name
     * @param expression
     */
    public BusinessExpression(String name, String expression) {
        if (name == null || "".equals(name.trim()) || expression == null || "".equals(expression.trim())) {
            throw new InvalidParameterException("The name or the expression cannot be empty");
        }
        this.name = name.trim();
        this.expression = expression.trim();
    }

    public String getName() {
        return name;
    }

    public String getExpression() {
        return expression;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof BusinessExpression) {
            //表达式的名称或者内容一样则认为是同一个表达式
            if (this.name.equals(((BusinessExpression) obj).getName()) || this.expression.equals(((BusinessExpression) obj).getExpression())) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
